package com.yutel.system.struts.action;

import java.util.List;

import com.yutel.component.ExceptionUtils;
import com.yutel.system.repository.BusinessTableBean;
import com.yutel.system.service.IDmlService;
import com.yutel.system.struts.core.BaseAction;

/**
 * 数据管理操作action<br>
 * 暂时支持表的增，删操作，支持表列的增加、删除、更改数据类型及是否为空操作<br>
 * 
 */
public class DmlAction extends BaseAction {

	private IDmlService dmlService;
	private String keyWord;
	private String tableId;
	private int start;
	private int limit;
	private int totalCount;
	private boolean success = true;
	private String message;

	private List<BusinessTableBean> tableList;
	private BusinessTableBean table = new BusinessTableBean();

	public String listTable() {
		try {
			tableList = dmlService.queryTablesByKeyWord(keyWord);
			totalCount = tableList.size();
			int endIndex = start + limit;
			if (endIndex > tableList.size()) {
				endIndex = tableList.size();
			}
			tableList = tableList.subList(start, endIndex);
		} catch (Exception e) {
			ExceptionUtils.handleException(e);
		}
		return SUCCESS;
	}

	public String loadTable() {
		try {
			table = dmlService.queryTableById(tableId);
		} catch (Exception e) {
			ExceptionUtils.handleException(e);
		}
		return SUCCESS;
	}

	public String saveTable() {
		try {
			dmlService.saveTable(table);
		} catch (Exception e) {
			ExceptionUtils.handleException(e);
		}
		return SUCCESS;
	}

	public String dropTable() {
		try {
			dmlService.dropTable(tableId);
		} catch (Exception e) {
			ExceptionUtils.handleException(e);
		}
		return SUCCESS;
	}

	public IDmlService getDmlService() {
		return dmlService;
	}

	public void setDmlService(IDmlService dmlService) {
		this.dmlService = dmlService;
	}

	public String getKeyWord() {
		return keyWord;
	}

	public void setKeyWord(String keyWord) {
		this.keyWord = keyWord;
	}

	public String getTableId() {
		return tableId;
	}

	public void setTableId(String tableId) {
		this.tableId = tableId;
	}

	public List<BusinessTableBean> getTableList() {
		return tableList;
	}

	public void setTableList(List<BusinessTableBean> tableList) {
		this.tableList = tableList;
	}

	public BusinessTableBean getTable() {
		return table;
	}

	public void setTable(BusinessTableBean table) {
		this.table = table;
	}

	public int getStart() {
		return start;
	}

	public void setStart(int start) {
		this.start = start;
	}

	public int getLimit() {
		return limit;
	}

	public void setLimit(int limit) {
		this.limit = limit;
	}

	public int getTotalCount() {
		return totalCount;
	}

	public void setTotalCount(int totalCount) {
		this.totalCount = totalCount;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public boolean isSuccess() {
		return success;
	}

	public void setSuccess(boolean success) {
		this.success = success;
	}

}
